_helo = _this select 0;
_class = _this select 1;
_spwn = _this select 2;
_payload = _this select 3;
_callsign = _this select 4;

//hint format ["%1",_this];

//if(_helo getVariable "RUM_inFlight")exitwith{hint "plnae in flight";};

_paytar = [];
RUM_ASclick = false;

openMap [true,true];
for [{_n=1},{_n<=3},{_n=_n+1}] do {
	_mkrname = "";
	_type = "";
	_hint = "";
	switch (_n) do {
		case 1: {
			_mkrname = format ["%1target",_helo];
			_type = "Destroy";
			_hint = "Select Target Area for CAS";
		};
		case 2: {
			_mkrname = format ["%1ingress",_helo];
			_type = "mil_start";
			_hint = "Select Ingress Point";
		};
		case 3: {
			_mkrname = format ["%1egress",_helo];
			_type = "mil_end";
			_hint = "Select Egress Point";
		};
		default {
			hint "shit";	
		};
	};
	_asloc = createMarkerLocal [_mkrname, [0,0,0]];
	_asloc setMarkerShapeLocal "ICON";
	_mkrname setMarkerTypeLocal _type;
	_stgtar = "";
	if(_n == 1)then{_stgtar = format ["'%1' setMarkerPosLocal _pos,RUM_ASclick = [_pos] call ROEzone",_mkrname]}else{_stgtar = format ["'%1' setMarkerPosLocal _pos,RUM_ASclick = true",_mkrname]};
	onMapSingleClick _stgtar;
	titleText [_hint, "PLAIN DOWN"];
	waitUntil {RUM_ASclick};
	onMapSingleClick "";
	if((_n == 2) or (_n == 3)) then {
		_mkrname2 = format ["%1target",_helo];
		_mkrname setMarkerDirLocal ((getMarkerPos _mkrname2 select 0)-(getMarkerPos _mkrname select 0)) atan2 ((getMarkerPos _mkrname2 select 1)-(getMarkerPos _mkrname select 1));
	};
	RUM_ASclick = false;
};
titleFadeOut 0;
sleep 1;
openMap [false,false];

_spwndir = getdir _spwn;

_helosave = _helo;
_helo = createVehicle [_class, getPos _spwn, [], 0, "FLY"];
removeAllweapons _helo;
_helo setVehicleVarName _helosave;
_helo setpos [(getpos _spwn select 0),(getpos _spwn select 1),(getpos _spwn select 2)+RUM_AHEL_flyHeight];
_helo setdir _spwndir;
_helo setVariable ["RUM_inFlight", true, true];

_grp = createGroup side player;
_pilot = _grp createUnit [RUM_AHEL_Pilot, getpos _spwn, [], 0, "FORM"];
_pilot moveinDriver _helo;
_gunner = _grp createUnit [RUM_AHEL_Pilot, getpos _spwn, [], 0, "FORM"];
_gunner moveinGunner _helo;
//if!(_gunner in crew _helo)then{deleteVehicle _gunner};

["immediatestrike",[player,_pilot,_callsign]] execVM (RUM_PATH+"AHel\radiodialogs.sqf");
sleep 16;

for [{_n=1},{_n<=3},{_n=_n+1}] do {
	_mkrname = "";
	switch (_n) do {
		case 1: {
			_mkrname = format ["%1ingress",_helo];
		};
		case 2: {
			_mkrname = format ["%1target",_helo];
		};
		case 3: {
			_mkrname = format ["%1egress",_helo];
		};
		default {
			hint "shit";	
		};
	};
	if(_n==2)then {
		_pos = getMarkerpos _mkrname;
		_wpAH=_grp addWaypoint [_pos, 0];
		_wpAH setWaypointStatements ["true", ""];
		_wpAH setWaypointType "SAD";
		_wpAH setWaypointSpeed "FULL";
		_wpAH setWaypointCombatMode "RED";
		_wpAH setWaypointCompletionRadius 700;	
		_helo flyInheight RUM_AHEL_flyHeight;
	} else {	
		_pos = getMarkerpos _mkrname;
		_wpAH=_grp addWaypoint [_pos, 0];
		_wpAH setWaypointStatements ["true", ""];
		_wpAH setWaypointType "MOVE";
		_wpAH setWaypointSpeed "NORMAL";
		_wpAH setWaypointCombatMode "BLUE";
		_wpAH setWaypointCompletionRadius 50;
		_helo flyInheight RUM_AHEL_flyHeight;
	};
};

fwp2=_grp addWaypoint [getpos _spwn, 0];
fwp2 setWaypointType "MOVE";
fwp2 setWaypointSpeed "FULL";
fwp2 setWaypointCombatMode "BLUE";
fwp2 setWaypointCompletionRadius 50;

sleep 45;
waitUntil{(!alive _helo) or (((((getPos _helo select 0) - (getpos _spwn select 0))^2+((getPos _helo select 1) - (getpos _spwn select 1))^2)^0.5) <= 100)};

sleep 1;
deleteVehicle _pilot;
deleteVehicle _gunner;
deleteVehicle _helo;

_mkrname1 = format ["%1ingress",_helo];
_mkrname2 = format ["%1target",_helo];
_mkrname3 = format ["%1egress",_helo];
deletemarkerLocal _mkrname1;
deletemarkerLocal _mkrname2;
deletemarkerLocal _mkrname3;

//_helo setVariable ["RUM_inFlight", false, true];

if(true)exitwith{};
